package org.byqh.dqeai.controller;

import io.swagger.v3.oas.annotations.tags.Tag;
import org.byqh.dqeai.common.Json;
import org.byqh.dqeai.entity.SysAsstApp;
import org.byqh.dqeai.entity.proxy.SysAsstAppProxy;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/sysAsstApp")
@Tag(name = "系统[SysAsstApp] - 辅助应用管理")
public class SysAsstAppController extends BaseOpController<SysAsstApp, SysAsstAppProxy> {
    /**
     * 根据分类ID，获取应用
     */
    @GetMapping(value = "/listByCategoryId")
    public Json<List<SysAsstApp>> listByCategoryId(
            @RequestParam String categoryId) {

        var list = getEntityQueryable()
                .where(s -> s.categoryId().eq(categoryId))
                .toList();

        return Json.success(list);
    }

    /**
     * 根据关键字，获取应用
     */
    @GetMapping(value = "/listByKeyword")
    public Json<List<SysAsstApp>> listByKeyword(
            @RequestParam String keyword) {

        var list = getEntityQueryable()
                .where(s -> s.or(() -> {
                    s.moduleName().like(keyword);
                    s.csFilepath().like(keyword);
                }))
                .toList();

        return Json.success(list);
    }
}